import { IConstraint } from "./Constaint";
import { Emitter } from "./Emitter";
import { ForceField } from "./ForceField";
import { Tween } from "./Tween";

export class ParticleSystem {
    emitters: Emitter[];
    forces: ForceField[];
    constraints: IConstraint[] = [];
    tweens: Tween<any>[] = [];
    time: number = 0;

    constructor(emitters: Emitter[], forces: ForceField[] = [], tweens: Tween<any>[] = [],constraints:IConstraint[]=[]) {
        this.emitters = emitters;
        this.forces = forces;
        this.tweens = tweens;
        this.constraints = constraints;
    }

    update(deltaTime: number) {
        this.time += deltaTime;
        for (let emitter of this.emitters) {
            for (let force of this.forces) {
                force.enabled && force.update(deltaTime, emitter.particles);
            }
            for (let constraint of this.constraints) {
                constraint.enabled && constraint.update( emitter.particles);
            }
            for (let tween of this.tweens) {
                tween.enable&& tween.update(this.time, emitter.particles);
            }
            emitter.update(deltaTime);
        }
    }
}